package com.itheima.test0910.test01;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

public class LocalDateTimeTest {
    public static void main(String[] args) {
        //当前系统时间：2020-09-10T10:56:39.149531400
        LocalDateTime now = LocalDateTime.now();
        System.out.println("当前系统时间：" + now);

        //指定时间获取对象:2020-09-10T10:55:34
        LocalDateTime ldt = LocalDateTime.of(2020, 9, 10, 10, 55, 34);
        System.out.println("指定时间获取对象:" + ldt);

        //获取年份:2020
        int year = now.getYear();
        System.out.println("获取年份:" + year);
        //获取月份:9
        int monthValue = now.getMonthValue();
        System.out.println("获取月份:" + monthValue);
        //获取天
        //一月当中的第几天(日期):10
        int dayOfMonth = now.getDayOfMonth();
        System.out.println("一月当中的第几天(日期):" + dayOfMonth);
        //一年当中第几天:254
        int dayOfYear = now.getDayOfYear();
        System.out.println("一年当中第几天:" + dayOfYear);
        //获取时:11
        int hour = now.getHour();
        System.out.println("获取时:" + hour);
        //获取分:23
        int minute = now.getMinute();
        System.out.println("获取分:" + minute);
        //获取秒:46
        int second = now.getSecond();
        System.out.println("获取秒:" + second);

        //将LocalDateTime拆分为LocalDate：2020-09-10
        LocalDate localDate = now.toLocalDate();
        System.out.println("将LocalDateTime拆分为LocalDate：" + localDate);
        //将LocalDateTime拆分为LocalTime：11:36:25.370506500
        LocalTime localTime = now.toLocalTime();
        System.out.println("将LocalDateTime拆分为LocalTime：" + localTime);
    }
}
